﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WcfServiceDuplex;
using System.Threading;
using System.ServiceModel;

namespace ConsoleServiceConsumer
{
	public class Program 
	{
		private static AutoResetEvent resetEvent;

		static void Main(string[] args)
		{
			Console.WriteLine("Consumer begin running");

			Thread.Sleep(TimeSpan.FromSeconds(3));

			resetEvent = new AutoResetEvent(false);

			InstanceContext callbackInstance = new InstanceContext(new MyCallback(resetEvent));
			System.ServiceModel.Channels.Binding wsBin = new WSDualHttpBinding();
			EndpointAddress endpointAddr = new EndpointAddress("http://localhost:1010/DuplexService");

			wsBin.OpenTimeout = TimeSpan.FromMinutes(1);

			using (MyServiceReference.MyServiceClient client = new MyServiceReference.MyServiceClient(callbackInstance))
			{
				client.SendMessage("Cawa laka daka");

				resetEvent.WaitOne();
			}

			Console.WriteLine("Consumer ended");

			Console.ReadLine();
		}

		
	}

	public class MyCallback : IMyCallback
	{
		private AutoResetEvent m_reset;

		public MyCallback()
		{
		}

		public MyCallback(AutoResetEvent reset)
		{
			m_reset = reset;
		}

		public void SendMessageCallback(string str)
		{
			Console.WriteLine("Enter in callback function");

			Console.WriteLine(str);
			m_reset.Set();
		}


		public void ReceiveMessage(string message)
		{
			throw new NotImplementedException();
		}
	}

}
